import {message} from 'antd';
import {formatMessage} from './intl';

export const newOrUpdateOrderValidator = data => {
    const requiredFields = [];
    if(!data.code)
        requiredFields.push(formatMessage({
            id: 'validator.message.code',
            defaultMessage: '编号'
        }));
    if(!data.name)
        requiredFields.push(formatMessage({
            id: 'validator.message.name',
            defaultMessage: '名称'
        }));
    if(!data.dealerCode)
        requiredFields.push(formatMessage({
            id: 'validator.message.dealerCode',
            defaultMessage: '所属总代编号'
        }));
    if(!data.dealerName)
        requiredFields.push(formatMessage({
            id: 'validator.message.dealerName',
            defaultMessage: '所属总代名称'
        }));
    if(requiredFields.length > 0) {
        message.warning(`${requiredFields.join('，')}${formatMessage({
            id: 'validator.message.required',
            defaultMessage: '必填!'
        })}`);
        return false;
    }
    return true;
};
